"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const cmd = 'chcp 65001 && tasklist /FO CSV';
const getSysTaskList = () => {
    return new Promise((resolve, reject) => {
        try {
            (0, child_process_1.exec)(cmd, (error, stdout, stderr) => {
                if (error) {
                    console.error(`exec error: ${error}`);
                    return;
                }
                if (stderr) {
                    console.error(`stderr: ${stderr}`);
                    return;
                }
                const lines = stdout.split('\r\n');
                lines.shift();
                lines.shift();
                lines.pop();
                const processes = lines.map((line) => {
                    const parts = line.split('","').map((item) => item.replaceAll('"', ''));
                    return {
                        ImageName: parts[0],
                        PID: Number(parts[1]),
                        SessionName: parts[2],
                        SessionNumber: parts[3],
                        MemUsage: parts[4]
                    };
                });
                resolve(processes);
            });
        }
        catch (err) {
            console.log('getSysTaskList error');
            resolve([]);
        }
    });
};
exports.default = getSysTaskList;
